﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Converters;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Data;
using System.IO;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using SuperFind.Lib.Core;

namespace SuperFind.Converters
{
    public class FileIconConverter : MarkupExtension, IMultiValueConverter
    {

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string filePath = values[0] as string;
            int fileType = System.Convert.ToInt32(values[1]);
            ImageSourceConverter img = new ImageSourceConverter();
            object icon = null;
            switch (fileType)
            {
                case 0:
                    icon = img.ConvertFromString("pack://application:,,/images/folder.png");
                    break;
                case 1:
                    //img.ConvertFromIcon(System.Drawing.Icon.ExtractAssociatedIcon(filePath));
                    icon = img.ConvertFromIcon(System.Drawing.Icon.ExtractAssociatedIcon(filePath));
                    break;
                default:
                    break;
            }
            return icon;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
